//	Grade32.h : Various utilities header file
//
#pragma once

#include "../GradeIface.h"

#include <boost/type_traits.hpp>
#include <iostream>
#include <string>

#define	MAX_BUF_SIZE	1024

namespace gKad {
	class GradeUtils {

	public:

		// Transforms string into TGradeAddr
		//
		static TGradeAddr String2GradeAddr(std::string *);

		// Logs message into deffined logger
		//
		template <typename T>
		void static serverLog(ILogger *logger, char *header, T message) {
			if(::boost::is_integral<T>::value) {
				char buf[MAX_BUF_SIZE] = {'\0'};
				(header == NULL) ? sprintf_s(buf, "%d", message) 
					: sprintf_s(buf, "%s %d", header, message);
				logger->LogString(buf);
			} else if (::boost::is_float<T>::value) {
				char buf[MAX_BUF_SIZE] = {'\0'};
				(header == NULL) ? sprintf_s(buf, "%d", message) 
					: sprintf_s(buf, "%s %d", header, message);
				logger->LogString(buf);
			} else {
				// it's not a number let's threat it as a char
				char buf[MAX_BUF_SIZE] = {'\0'};
				(header == NULL) ? sprintf_s(buf, "%s", message) 
					: sprintf_s(buf, "%s %s", header, message);
				logger->LogString(buf);
			}
		}

	protected:

	private:

	};
}